package cn.tedu.charging.device.controller;

import cn.tedu.charging.common.pojo.JsonResult;
import cn.tedu.charging.common.pojo.param.GunStatusUpdateParam;
import cn.tedu.charging.common.pojo.vo.StationInfoVO;
import cn.tedu.charging.device.service.DeviceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/device")
@Api(tags = "设备模块")
public class DeviceController {

    @Autowired
    private DeviceService deviceService;

    /*
    * 获取场站信息
    * 入参:gunId
    * 出参:场站信息StationInfoVO
    * 调用方式:GET
    * */
    @ApiOperation(value = "获取场站信息")
    @GetMapping("/station/info/{gunId}")
    public JsonResult<StationInfoVO> getStationInfo(@PathVariable Integer gunId){
        log.debug("获取场站信息-入参:{}",gunId);
        log.debug("获取场站信息-deviceService:入参:{}",gunId);
        StationInfoVO stationInfoVO = deviceService.getStationInfo(gunId);
        log.debug("获取场站信息-deviceService:入参:{},出参:{}",gunId,stationInfoVO);
        JsonResult<StationInfoVO> result = JsonResult.ok(stationInfoVO,"获取场站信息成功");
        log.debug("获取场站信息-入参:{},出参:{}",gunId,result);
        return result;
    }

    /*
    * 更新枪的状态
    * 入参:gunId,status
    * 出参:Boolean
    * 调用方式:POST
    * */
    @ApiOperation(value = "更新枪的状态")
    @PostMapping("/gun/status")
    public JsonResult<Boolean> updateGunStatus(@RequestBody GunStatusUpdateParam gunStatusUpdateParam){
        log.debug("更新枪的状态-入参:{}",gunStatusUpdateParam);
        log.debug("更新枪的状态-deviceService:入参:{}",gunStatusUpdateParam);
        Boolean result = deviceService.updateGunStatus(gunStatusUpdateParam);
        log.debug("更新枪的状态-deviceService:入参:{},出参:{}",gunStatusUpdateParam,result);
        JsonResult<Boolean> jsonResult = JsonResult.ok(result,"更新枪的状态成功");
        log.debug("更新枪的状态-入参:{},出参:{}",gunStatusUpdateParam,jsonResult);
        return jsonResult;
    }
}
